﻿@{
    ViewBag.Title = "Tra cứu";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="row-fluid">
    <div class="span12">
        <!-- BEGIN SAMPLE FORM PORTLET-->
        <div class="portlet box blue">
            <div class="portlet-title">
                <h4><i class="icon-reorder"></i>Kết quả học tập</h4>
                <div class="tools">
                    <a href="javascript:;" class="collapse"></a>
                    <a href="#portlet-config" data-toggle="modal" class="config"></a>
                    <a href="javascript:;" class="reload"></a>
                    <a href="javascript:;" class="remove"></a>
                </div>
            </div>
            <div class="portlet-body form">
                <p>
                    @(Html.Kendo().AutoComplete()
                        .Name("TuKhoa")
                        .Filter("startswith")
                        .DataTextField("Text")
                        .Placeholder("Nhập từ khóa...")
                        .HtmlAttributes(new { style = "width: 300px" })
                        .DataSource(source =>
                        {
                            source.Read(read =>
                            {
                                read.Action("TuKhoa", "TraCuu")
                                    .Data("getTuKhoa");
                            })
                            .ServerFiltering(true);
                        })
                        .Events(e => {
                            e.Change("reloadChuyenNganh");
                        })
                    )
                </p>
                <p>
                    @(Html.Kendo().DropDownList()
                        .Name("ID_dt")
                        .OptionLabel("Chọn chuyên ngành")
                        .DataTextField("Text")
                        .DataValueField("Value")
                        .HtmlAttributes(new { style = "width:200px;" })
                        .DataSource(source =>
                        {
                            source.Read(read =>
                            {
                                read.Action("getChuyenNganh", "TraCuu")
                                    .Data("getTuKhoa")
                                    ;
                            })
                            .ServerFiltering(true)
                            ;
                        })
                        .Events(e => {
                            e.DataBound("ID_dt_DataBound");
                        })
                            //.Enable(false)
                        .AutoBind(false)
                            //.CascadeFrom("TuKhoa")
                    )


                    @(Html.Kendo().DropDownList()
                        .Name("NamHoc")
                        .OptionLabel("Toàn khóa")
                        .HtmlAttributes(new { style = "width:120px" })
                        .DataTextField("Text")
                        .DataValueField("Value")
                        .DataSource(source =>
                        {
                            source.Read(read =>
                            {
                                read.Action("NamHoc", "TraCuu")
                                    .Data("getTuKhoa");
                            })
                            .ServerFiltering(true)
                            ;
                        })
                        //.Enable(false)
                        .AutoBind(false)
                        .CascadeFrom("ID_dt")
                    )

                    @(Html.Kendo().DropDownList()
                        .Name("HocKy")
                        .HtmlAttributes(new { style = "width:120px" })
                        .OptionLabel("Cả năm")
                        .DataTextField("Text")
                        .DataValueField("Value")
                        .DataSource(source =>
                        {
                            source.Read(read =>
                            {
                                read.Action("HocKy", "TraCuu")
                                    .Data("getTuKhoa");
                            }).ServerFiltering(true);
                        })
                        //.Enable(false)
                        .AutoBind(false)
                        .CascadeFrom("NamHoc")
                    )
                    <button class="btn blue" id="TraCuuButton">Tra cứu</button>&nbsp;
                    <button class="btn green" id="btnXuatBangDiem">Xuất bảng điểm</button>
                </p>
                <p></p>
                @(Html.Kendo().Grid<StudentPortal.ViewModels.DiemHocTap>()
                    .Name("GridBangDiem")
                    .Columns(columns =>
                    {
                        columns.Bound(diem => diem.Ma_mon).Width(50);
                        columns.Bound(diem => diem.Ten_mon).Width(150);
                        columns.Bound(diem => diem.He_so).Width(30);
                        columns.Bound(diem => diem.X).Width(30);
                        columns.Bound(diem => diem.Y).Width(30);
                        columns.Bound(diem => diem.Z).Width(30).Format("{0:0.00}");
                        columns.Bound(diem => diem.Diem_chu).Width(50);
                        columns.Bound(diem => diem.Nam_hoc).Width(100).Hidden();
                        columns.Bound(diem => diem.Hoc_ky).Width(50).Hidden();
                        columns.Template(@<text></text>).ClientTemplate("<div class='changeRowColor' Diem_chu='#=Diem_chu#'").Hidden();
                    })
                    .Groupable()
                    .Pageable()
                    .Sortable()
                    .Selectable()
                    .Pageable(pager => pager.Enabled(false))
                    .DataSource(
                        dataSource => dataSource.Ajax()
                                .Group(group => group.Add(diem => diem.Nam_hoc))
                                .Group(group => group.Add(diem => diem.Hoc_ky))
                            .Read(read => read.Action("DiemHocTap", "TraCuu").Data("getTuKhoa"))
                    )
                    .HtmlAttributes(new { style = "min-height:400px" })
                            .Events(e => { e.DataBound("GridBangDiem_DataBound"); })
                )
            </div>
        </div>
    </div>
</div>
@if(ViewBag.IsSinhVien){
        <div id="SinhVien" Ma_sv ="@User.Identity.Name"></div>
    }
<style>
    .Diem_F {
        background-color:#F2DEDE;
        border: 1px solid;
        /*color: #fff;*/
    }
</style>
<script type="text/javascript">
    $(document).ready(function () {
        $('#SinhVien').each(function () {
            $('#TuKhoa').val($(this).attr('Ma_sv'));
            reloadChuyenNganh();
        });
    });
    function GridBangDiem_DataBound() {
        $('.changeRowColor').each(function () {
            if ($(this).attr('Diem_chu') == 'F') {
                $(this).parent().parent().addClass('Diem_F');
            }
        });
    }
    function reloadChuyenNganh(e) {
        $('#ID_dt').data('kendoDropDownList').dataSource.read();
    }
    function getTuKhoa() {
        return {
            ID_dt: $('#ID_dt').val(),
            TuKhoa: $("#TuKhoa").val(),
            NamHoc: $("#NamHoc").val(),
            HocKy: $("#HocKy").val()
        };
    }
    function ID_dt_DataBound() {
        var t = $('#ID_dt').data('kendoDropDownList');
        t.value(t.dataSource._data[0].Value);
    }
    $("#TraCuuButton").click(function () {
        $("#GridBangDiem").data("kendoGrid").dataSource.read();
    });

</script>
